<div class="myRightType">
	<div class="title">
		管理员列表
	</div>
	<div class="inner clearfix">
		<div class="box clearfix">
			<div class="row">
				<div class="col-md-2">
					<p>管理员列表</p>
				</div>
				<div class="col-md-10 tr">
					<a href="javascript:;" class="rfoat" id="addAdmin"> <i class="glyphicon glyphicon-plus"></i></a>

					<div class="search rfoat">
						<input type="text" placeholder="输入账号"  id="username2"/>
						<i class="glyphicon glyphicon-search" id="seachPass"></i>

					</div>

				</div>
			</div>
			<br />
			<table id="AccountList" class="clearfix"></table>

		</div>

	</div>
</div>
<div id="newAdminNew">
	<input type="text" placeholder="账号" id="username" />
	<input type="password" placeholder="密码" id="password1" />
	<input type="password" placeholder="确认密码" id="password2" />
	<input type="text" placeholder="邮箱" id="email" />

	<button type="button" class="btn btn-primary" id="sure" onclick="sure()">确定</button>

</div>
<div id="pass" style="display: none;">

	<!--<input type="password" placeholder="原密码" id="password"/>-->
	<input type="password" placeholder="新密码" id="newPass" />
	<input type="password" placeholder="确认密码" id="newPass2" />
	<button type="button" class="btn btn-primary" id="sureChangePass">确定</button>

</div>
<script type="text/javascript">
	//添加管理员
	$("#addAdmin").click(function() {

		alertNew("新建管理员", "660", "570", $("#newAdminNew"));

	})

	function sure() {
      var re = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
		if($("#username").val() == "" || $("#password1").val() == "" || $("#password2").val() == "") {
			prompt("账号密码不能为空！");
		} else if($("#email").val() == "") {
			prompt("邮箱不能为空！");

		}else if(!re.test($('#email').val())) {
			prompt("邮箱格式不正确！");

		} else if($("#password1").val() != $("#password2").val()) {
			prompt("确认密码错误！");
		} else {

			$.ajax({
				type: "post",
				url: "/wechat_mt5/admin/add/manager",
				data: {
					username: $('#username').val(),
					password: $('#password1').val(),
					mail: $('#email').val()

				},
				success: function(data) {
					if(data.code == 0) {
						prompt("添加成功！");
						$('#AccountList').bootstrapTable(
							"refresh", {
								url: "/wechat_mt5/admin/list/manager"
							}
						);
					} else {
						prompt("添加失败！");
					}
				},
				error:function(data){
					if(code==10010003){
						prompt("您没有权限！");
					}
				}

			})
		}
	}
	//查找
	function lookUserName(){
		var user = $("#username2").val();
			$('#AccountList').bootstrapTable('refresh', {
				query: {
					username: user,

				}
			});
	}
	$("#seachPass").click(function() {
		lookUserName();
	})
	
	
	document.onkeydown = function(e) {
		var ev = document.all ? window.event : e;
		if(ev.keyCode == 13) {
		      lookUserName();

		}
	}

	$('#AccountList').bootstrapTable({
		url: "/wechat_mt5/admin/list/manager",
		method: 'get',
		columns: [{
			field: 'username',
			title: '账号'
		}, {
			field: 'mail',
			title: '邮箱',

		}, {
			field: 'createTime',
			title: '创建时间',
			formatter: date,
		}, {
			field: 'id',
			title: '操作',
			formatter: changePass,
		}],
		height: 650,
		pageSize: 10,
		pageList: [10, 25, 50, 100],
		showRefresh: true,
		editable: true,
		// onClickRow:operateEvents,
		// showColumns: true,
		pagination: true,
//		  striped: true,
		sidePagination: 'server',

	});

	$("#sureChangePass").click(function() {
		if($('#newPass').val() != $('#newPass2').val()) {
			prompt("确认密码错误！");
		} else {
			$.ajax({
				type: "put",
				url: "/wechat_mt5/admin/update/manager/password",
				data: {
					managerId: sessionStorage.getItem("changeAdminId"),
					newPassword: $('#newPass').val(),
					updateTime:sessionStorage.getItem("changeAdminUpadteTime")*1

				},
				success: function(data) {

					if(data.code == 0) {
						prompt("更改成功！");
					} else {
						if(data.code = 10040001) {
							prompt("更改失败")
						}
					}
				}

			})
		}
	})

	function changePass(value, row, index) {
		var info=JSON.stringify(row)
		return [
				"<button type='button' class='btn btn-primary' onclick='changePassAlert(" + info + ")'>修改密码</button>",

			].join("")
			// return ;  
	}

	function changePassAlert(info) {
		alertNew("更改管理员密码", "660", "400", $("#pass"));

		sessionStorage.setItem("changeAdminId",info.id);
		sessionStorage.setItem("changeAdminUpadteTime",info.updateTime);
		
	}
</script>